<?php
require_once dirname(dirname(__FILE__)) . '/config/config.php';
require_once DOCUMENT_ROOT . DIR_SHARED_DAO . "dao_cinema.php";
require_once DOCUMENT_ROOT . DIR_SHARED_DAO . "dao_city.php";
require_once DOCUMENT_ROOT . DIR_SHARED_DAO . "dao_cinema.php";
require_once DOCUMENT_ROOT . DIR_SHARED_LIBRARIES . 'lib_sql_convert.php';


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of api_security
 *
 * @author Thien
 */
class api_cinemas {
    
    public static function save_cinema($cinema_id, $name, $address, $image, $city_id, $latitude, $longitude) {
        $dao_cinema = new dao_cinema();
        return $dao_cinema->save($cinema_id, $name, $address, $image, $city_id, $latitude, $longitude);
    }
    
    public static function delete_cinema($cinema_id) {
        $dao_cinema = new dao_cinema();
        return $dao_cinema->delete($cinema_id);
    }
    
    public static function get_cinema_by_id($cinema_id) {
        $dao_cinema = new dao_cinema();
        return $dao_cinema->get_by_id($cinema_id);
    }
    
    public static function get_all_cinemas() {
        $dao_cinema = new dao_cinema();
        return $dao_cinema->get_all();
    }
    
    public static function get_all_cinemas_with_now_showing() {
        $dao_cinema = new dao_cinema();
        $status_id = 2; //for now showing
        return $dao_cinema->get_all_by_status_id($status_id);
    }
    
    public static function get_all_cinemas_with_comming_soon() {
        $dao_cinema = new dao_cinema();
        $status_id = 1; //for comming soon
        return $dao_cinema->get_all_by_status_id($status_id);
    }
    
    public static function get_all_cities() {
        $dao_city = new dao_city();
        return $dao_city->get_all();
    }
    
    public static function get_city_id_from_name($name) {
        $dao_city = new dao_city();
        $city = $dao_city->get_id_by_name($name);
        return $city['id'];
    }
    
    public static function get_city_by_id($city_id) {
        $dao_city = new dao_city();
        $city = $dao_city->get_by_id($city_id);
        return $city;
    }
    
    public static function validate_cinema_fields($name_save, $address_save, $image_save, $city_save, $latitude_save, $longitude_save) {
        $error_show = "";
        if (empty($name_save)) {
            $error_show .= "<li>Please fill a Name.</li>";
        }
        if (empty($address_save)) {
            $error_show .= "<li>Please fill a Address.</li>";
        }
        if (empty($city_save)) {
            $error_show .= "<li>Please choose a City.</li>";
        }
        if (empty($latitude_save)) {
            $error_show .= "<li>Please upload a Latitude.</li>";
        }
        if (empty($longitude_save)) {
            $error_show .= "<li>Please upload a Longitude.</li>";
        }
        if (empty($image_save)) {
            $error_show .= "<li>Please upload a Image.</li>";
        }
        return $error_show;
    }
    
    public static function get_default_city() {
        $dao_city = new dao_city();
        $city = $dao_city->get_first();
        if (!empty($city['name'])) {
            return $city['name'];
        }
        return "";
    }
}
